package com.waves.core.config;

import com.waves.core.constant.MQConstant;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.Exchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * @author dlw
 * rabbitmq交换机与队列创建配置
 * 容器中的Queue、Exchange、Binding会自动创建（在RabbitMQ）不存在的情况下
 */
@Configuration
public class MyRabbitMQConfig {

    /**
     * 交换机
     *
     * @return
     */
    @Bean
    public Exchange orderEventExchange() {
        return new TopicExchange(MQConstant.ORDER_EVENT_EXCHANGE, true, false);
    }

    @Bean
    public Exchange messageRecordExchange() {
        return new TopicExchange(MQConstant.MESSAGE_RECORD_EXCHANGE, true, false);
    }



    /**
     * 消息发送队列
     * @return
     */
    @Bean
    public Queue chatSendMesQueue() {
        return new Queue(MQConstant.CHAT_SEND_MSG_QUEUE, true, false, false);
    }

    /**
     * webSocket主动推送队列
     * @return
     */
    @Bean
    public Queue websocketPushQueue() {
        return new Queue(MQConstant.WEBSOCKET_PUSH_MSG_QUEUE, true, false, false);
    }

    /**
     * 订单释放队列
     * @return
     */
    @Bean
    public Queue orderReleaseQueue() {
        return new Queue(MQConstant.ORDER_RELEASE_ORDER_QUEUE, true, false, false);
    }

    /**
     * 库存释放队列
     * @return
     */
    @Bean
    public Queue stockReleaseQueue() {
        return new Queue(MQConstant.STOCK_RELEASE_STOCK_QUEUE, true, false, false);
    }

    /**
     * 商品秒杀队列
     * @return
     */
    @Bean
    public Queue orderSecKillOrderQueue() {
        return new Queue(MQConstant.ORDER_SEC_KILL_ORDER_QUEUE, true, false, false);
    }

    /**
     * 扫码通知队列
     * @return
     */
    @Bean
    public Queue scanMsgQueue() {
        return new Queue(MQConstant.SCAN_MSG_QUEUE, true, false, false);
    }


    /**
     * 消息中心对列
     * @return
     */
    @Bean
    public Queue messageRecordQueue() {
        return new Queue(MQConstant.MESSAGE_RECORD_QUEUE, true, false, false);
    }



    /**
     * 队列绑定交换机
     * @return
     */

    @Bean
    public Binding orderReleaseBinding() {
        return new Binding(MQConstant.ORDER_RELEASE_ORDER_QUEUE,
                Binding.DestinationType.QUEUE,
                MQConstant.ORDER_EVENT_EXCHANGE,
                MQConstant.ORDER_RELEASE_KEY,
                null);
    }

    @Bean
    public Binding orderReleaseOtherBinding() {
        return new Binding(MQConstant.STOCK_RELEASE_STOCK_QUEUE,
                Binding.DestinationType.QUEUE,
                MQConstant.ORDER_EVENT_EXCHANGE,
                MQConstant.ORDER_RELEASE_OTHER_KEY,
                null);
    }

    @Bean
    public Binding chatSendMsgBinding() {
        return new Binding(MQConstant.CHAT_SEND_MSG_QUEUE,
                Binding.DestinationType.QUEUE,
                MQConstant.ORDER_EVENT_EXCHANGE,
                MQConstant.CHAT_SEND_MSG,
                null);
    }

    @Bean
    public Binding websocketPushBinding() {
        return new Binding(MQConstant.WEBSOCKET_PUSH_MSG_QUEUE,
                Binding.DestinationType.QUEUE,
                MQConstant.ORDER_EVENT_EXCHANGE,
                MQConstant.WEBSOCKET_PUSH_MSG,
                null);
    }

    @Bean
    public Binding orderSecKillOrderQueueBinding() {
        return new Binding(MQConstant.ORDER_SEC_KILL_ORDER_QUEUE,
                Binding.DestinationType.QUEUE,
                MQConstant.ORDER_EVENT_EXCHANGE,
                MQConstant.ORDER_SEC_KILL_ORDER,
                null);
    }

    @Bean
    public Binding scanMsgBinding() {
        return new Binding(MQConstant.SCAN_MSG_QUEUE,
                Binding.DestinationType.QUEUE,
                MQConstant.ORDER_EVENT_EXCHANGE,
                MQConstant.SCAN_MSG,
                null);
    }

    @Bean
    public Binding messageRecordBinding() {
        return new Binding(MQConstant.MESSAGE_RECORD_QUEUE,
                Binding.DestinationType.QUEUE,
                MQConstant.MESSAGE_RECORD_EXCHANGE,
                MQConstant.MESSAGE_RECORD_KEY,
                null);
    }


}
